package Stringtest4;

import java.util.Random;
import java.util.Scanner;
///随机生成验证码

public class Stringtest5 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请你输入要生成的验证码的位数：");
        int number =input.nextInt();
        yanzhengma(number);
    }
    public static int yanzhengma(int number){
        Random ra= new Random();
        String code="";///定义一个变量用来接受下面不同类型的数据
        for (int i=0;i<number;i++) {
            int sui = ra.nextInt(3);
            switch (sui){
                case 0:
                    int x= ra.nextInt(10);
                    code +=x;
                    break;
                case 1:
                    char Chars=(char) (ra.nextInt(26)+97);
                    code +=Chars;
                    break;
                case 2:
                    char chars=(char) (ra.nextInt(26)+65);
                    code +=chars;
                    break;
            }
        }
        System.out.println("本次生成验证码是"+code);
        return number;
    }

}
